﻿using System;
using System.Collections.Generic;
 
using System.Text;
using System.Runtime.InteropServices;


namespace HDF5
{
    using hid_t = System.Int32;
    using herr_t = System.Int32;
    using hsize_t = System.UInt64;
    using hssize_t = System.Int64;
    using hunsigned = System.UInt32;

    using hbool_t = System.UInt32;
    using htri_t = System.Int32;
    using sszie_t = System.Int64;

    using haddr_t = System.UInt64;

    using uint32_t = System.UInt32;
    using uint64_t = System.UInt64;

    using H5O_msg_crt_idx_t = System.UInt32;

    using size_t = System.UInt32;

    using off_t = System.Int32;

    using H5E_major_t = System.Int32;
    using H5E_minor_t = System.Int32;



    #region enums
    public enum H5G_obj_t {
        H5G_UNKNOWN = -1,		/* Unknown object type		*/
        H5G_LINK,		        /* Object is a symbolic link	*/
        H5G_GROUP,		        /* Object is a group		*/
        H5G_DATASET,		/* Object is a dataset		*/
        H5G_TYPE,			/* Object is a named data type	*/
        H5G_RESERVED_4,		/* Reserved for future use	*/
        H5G_RESERVED_5,		/* Reserved for future use	*/
        H5G_RESERVED_6,		/* Reserved for future use	*/
        H5G_RESERVED_7		/* Reserved for future use	*/
    } 


    /* Types of link storage for groups */
    public enum H5G_storage_type_t {
        H5G_STORAGE_TYPE_UNKNOWN = -1,	/* Unknown link storage type	*/
        H5G_STORAGE_TYPE_SYMBOL_TABLE,      /* Links in group are stored with a "symbol table" */
                                            /* (this is sometimes called "old-style" groups) */
        H5G_STORAGE_TYPE_COMPACT,		/* Links are stored in object header */
        H5G_STORAGE_TYPE_DENSE 		/* Links are stored in fractal heap & indexed with v2 B-tree */
    }
    #endregion enums

    #region structs
    /* Information struct for group (for H5Gget_info/H5Gget_info_by_name/H5Gget_info_by_idx) */
    public struct H5G_info_t {
        H5G_storage_type_t 	storage_type;	/* Type of storage for links in group */
        hsize_t 	nlinks;		        /* Number of links in group */
        System.Int64     max_corder;             /* Current max. creation order value for group */
    }
    #endregion structs

    #region delegates
    /* Prototype for H5Giterate() operator */
    public delegate herr_t H5G_iterate_t(hid_t group, [In][MarshalAs(UnmanagedType.LPStr)] string name, IntPtr op_data);
    #endregion delegates

    public static class H5G
    {

        public static int H5G_NTYPES	=256;
        public static int H5G_NLIBTYPES = 8;

        // imports
        #region Group functions
        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gcreate( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, size_t size_hint )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gcreate( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id ) ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gcreate2( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gcreate_anon( hid_t loc_id, hid_t gcpl_id, hid_t gapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gopen( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gopen( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t gapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gopen2( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string name, hid_t gapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Gclose(hid_t group_id)  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Gget_info( hid_t group_id, ref H5G_info_t group_info )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern herr_t H5Gget_info_by_name( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string group_name, ref H5G_info_t group_info, hid_t lapl_id )  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern hid_t H5Gget_create_plist(hid_t group_id)  ;

        [DllImport("hdf5dll.dll",CharSet=CharSet.Ansi)]
        public static extern  herr_t H5Gget_info_by_idx( hid_t loc_id, [In][MarshalAs(UnmanagedType.LPStr)] string group_name, H5_index_t index_type, H5_iter_order_t order, hsize_t n, ref H5G_info_t group_info, hid_t lapl_id );


        #endregion Group functions


    }
}
